// oplog.go
package models_mongo

import (
	"martini_template/componnet"

	"gopkg.in/mgo.v2"
	_ "gopkg.in/mgo.v2/bson"
)

var session *mgo.Session
var mongoDb *mgo.Database

func init() {
	//connectMongodb()
}

func connectMongodb() {
	var err error
	host, _ := componnet.MongoConfig.GetValue(componnet.ENV, "host")
	port, _ := componnet.MongoConfig.GetValue(componnet.ENV, "port")
	connectionStr := "mongodb://" + host + ":" + port
	session, err = mgo.Dial(connectionStr)
	if err != nil {
		panic(err)
	}
	session.SetMode(mgo.Monotonic, true)
	dbname, _ := componnet.MongoConfig.GetValue(componnet.ENV, "dbname")
	mongoDb = session.DB(dbname)
}
